package com.lykj.llw.box.ui.activity

import android.os.Bundle
import android.view.View
import com.blankj.utilcode.util.KeyboardUtils
import com.gyf.immersionbar.BarHide
import com.gyf.immersionbar.ImmersionBar
import com.lykj.lib_base.base.BaseActivity
import com.lykj.lib_base.internal.extfun.clickWithTrigger
import com.lykj.lib_base.internal.utils.ToastUtils
import com.lykj.llw.box.databinding.ActEditPwdBinding

/**
 * ================================================
 * 修改密码页面
 * ================================================
 *
 * @author gosha
 * @date 2023/10/25-14:34
 */
class EditPwdActivity : BaseActivity() {
    lateinit var binding: ActEditPwdBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = ActEditPwdBinding.inflate(layoutInflater)
        setContentView(binding.root)

        initUI()
        initData()
        setListener()
    }

    override fun onResume() {
        super.onResume()

        ImmersionBar.with(this)
            .statusBarDarkFont(true) //状态栏字体是深色，不写默认为亮色
            .navigationBarDarkIcon(true)
            .hideBar(BarHide.FLAG_HIDE_NAVIGATION_BAR)
            .navigationBarEnable(false)
            .init()
    }

    override fun initUI() {
        binding.titleBar.tvTitle.text = "修改密码"
        binding.titleBar.tvRightOption.visibility = View.GONE
    }

    //修改密码
    private fun editPwd() {

    }

    //获取验证码
    private fun obtainYZM() {

    }

    override fun initData() {
    }

    override fun setListener() {
        binding.titleBar.ivBack.clickWithTrigger {
            finish()
        }

        binding.tvCode.clickWithTrigger(300) {
            if (binding.etPhone.text.toString().length != 11) {
                ToastUtils.showShort(this, "请输入正确的手机号码")
                return@clickWithTrigger
            }

            obtainYZM()
        }

        binding.tvBtnConfirm.clickWithTrigger(100) {
            if (binding.etPhone.text.length != 11) {
                ToastUtils.showShort(this@EditPwdActivity, "请输入正确的手机号码")
                return@clickWithTrigger
            }

            if (binding.etYzm.text.toString().isNullOrEmpty()) {
                ToastUtils.showShort(this@EditPwdActivity, "请输入验证码")
                return@clickWithTrigger
            }

            if (binding.etPwd.text.toString().isNullOrEmpty()) {
                ToastUtils.showShort(this@EditPwdActivity, "请输入新的密码")
                return@clickWithTrigger
            }

            if (!binding.etPwd.text.toString().equals(binding.etPwdAgain.text.toString())) {
                ToastUtils.showShort(this@EditPwdActivity, "两次输入的密码不一致")
                return@clickWithTrigger
            }

            editPwd()
        }

        KeyboardUtils.registerSoftInputChangedListener(this) {
            if (it == 0) {
                binding.etPhone.clearFocus()
                binding.etYzm.clearFocus()
                binding.etPwd.clearFocus()
                binding.etPwdAgain.clearFocus()
            }
        }
    }

    override fun onDestroy() {
        removeDisposables(this)
        super.onDestroy()
    }
}